package com.szewec.ps.util.dialog;

import android.app.Activity;
import android.content.Context;

import androidx.annotation.NonNull;

import com.szewec.ps.R;
import com.szewec.ps.util.imagepicker.SelectDialog;
import com.szewec.ps.util.imagepicker.manager.SelectionManager;

import java.util.List;

/**
 * 对话框
 *
 *
 */
public class SystemDialog {
    public static void showConfirm(@NonNull Context context, String title, String showContent, String confirmTitleName, @NonNull OkAction okAction, @NonNull CancelAction cancelAction) {
        final com.szewec.ps.util.dialog.CommonDialog commonDialog = new CommonDialog(context);
        commonDialog.setTitle(title);
        commonDialog.setContent(showContent);
        commonDialog.setEnsure(confirmTitleName);
        commonDialog.setOnEnsureClickListener(view -> {
            // 点击“确认”后的操作
            commonDialog.dismiss();
            okAction.onOk();
        });
        commonDialog.setOnCancelClickListener(view -> {
            commonDialog.dismiss();
            cancelAction.onCancel();
        });
        commonDialog.show();
    }

    public interface OkAction {
        void onOk();
    }

    public interface CancelAction {
        void onCancel();
    }

    /**
     * 打开选择对话框
     * @param activity activity
     * @param selectDialogListener 处理监听器
     * @param names 按钮名称集合
     * @return
     */
    public static SelectDialog showSelectDialog(@NonNull Activity activity, @NonNull SelectDialog.SelectDialogListener selectDialogListener, @NonNull List<String> names) {
        SelectionManager.getInstance().clearSelectedMediaFileList();//先清空选择记录
        SelectionManager.getInstance().removeAll();//清空选中记录
        SelectDialog dialog = new SelectDialog(activity, R.style.transparentFrameWindowStyle, selectDialogListener, names);
        if (!activity.isFinishing()) {
            dialog.show();
        }
        return dialog;
    }
}
